package com.itbupt.domain.strategy.model.entity;

import com.itbupt.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author dingchang
 * @Date 2025/3/18 15:15
 * @Description: 策略实体
 */

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {

    /** 抽奖策略ID */
    private Long strategyId;
    /** 抽奖策略描述 */
    private String strategyDesc;

    /** 抽奖规则模型 rule_weight,rule_blacklist */
    private String ruleModels;

    // 获取规则模型 - rule_weight,rule_blacklist - 以逗号分隔 - 划分为数组
    public String[] ruleModels() {
        if (StringUtils.isBlank(ruleModels)) {
            return null;
        }
        return ruleModels.split(Constants.SPLIT);
    }

    // 获取权重规则
    public String getRuleWeight() {
        String[] ruleModels = this.ruleModels();
        if (null == ruleModels) {
            return null;
        }
        for (String ruleModel : ruleModels) {
            if ("rule_weight".equals(ruleModel)) {
                return ruleModel;
            }
        }
        return null;
    }

}
